/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package commonlib.domain;

/**
 *
 * @author maria.cachon
 */
import java.io.*;
import java.util.ArrayList;
public class DictionaryDataManager {
	private String path;

    public DictionaryDataManager(String path) {
        this.path = path;
    }

    public void save(ArrayList<String> dictio)
    {
        try {
            File newTextFile = new File(path);
            FileWriter fw = new FileWriter(newTextFile);
            for (int i = 0; i < dictio.size(); i++) {
                System.out.println("import word "+dictio.get(i));
                fw.write(dictio.get(i)+"\n");
            }
            fw.close();
        }
        catch(IOException ie) {
            System.out.println("ERROR SAVE");
        }
    }

    public ArrayList<String> getDictionary()  {
        ArrayList<String> dictio = new ArrayList<String>();
        try {
        	File f = new File(path);
        	BufferedReader entrada;
        	entrada = new BufferedReader(new FileReader(f));
        	String linea;
        	while (entrada.ready()) {
        		linea = entrada.readLine();
        		System.out.println("load word "+linea);
        		dictio.add(linea);
             }
        	entrada.close();
        }
        catch(IOException ie) {
            System.out.println("ERROR GET");
        }
        return dictio;
    }

}